
//script by http://www.yvoschaap.com

//XMLHttpRequest class function
function datosServidor() {
};
datosServidor.prototype.iniciar = function() {
	try {
		// Mozilla / Safari
		this._xh = new XMLHttpRequest();
	} catch (e) {
		// Explorer
		var _ieModelos = new Array(
		'MSXML2.XMLHTTP.5.0',
		'MSXML2.XMLHTTP.4.0',
		'MSXML2.XMLHTTP.3.0',
		'MSXML2.XMLHTTP',
		'Microsoft.XMLHTTP'
		);
		var success = false;
		for (var i=0;i < _ieModelos.length && !success; i++) {
			try {
				this._xh = new ActiveXObject(_ieModelos[i]);
				success = true;
			} catch (e) {
			}
		}
		if ( !success ) {
			return false;
		}
		return true;
	}
}

datosServidor.prototype.ocupado = function() {
	estadoActual = this._xh.readyState;
	return (estadoActual && (estadoActual < 4));
}

datosServidor.prototype.procesa = function() {
	if (this._xh.readyState == 4 && this._xh.status == 200) {
		this.procesado = true;
	}
}

datosServidor.prototype.enviar = function(urlget,datos) {
	//alert(urlget);
	if (!this._xh) {
		this.iniciar();
	}
	if (!this.ocupado()) {
		this._xh.open("GET",urlget,false);
		this._xh.send(datos);
		
		if (this._xh.readyState == 4 && this._xh.status == 200) {
			//alert('window.location.reload();');
			window.location.reload();// refresh page
			return this._xh.responseText;
		}
		
	}
	return false;
}


//var urlBase = "http://localhost/smartbooktrunk/updater/update.php";window.location.href
var urlBase = getUpdatePath(window.location);
//var urlBase = "http://localhost/smartbooktrunk/updater/update.php";
var formVars = "";
var changing = false;
var uid = "";

function getUpdatePath(fullpath)
{
	var x = fullpath.toString().indexOf("index.php");
	var url = fullpath.toString().substring(0,x) + "updater/update.php";
	//alert(url);
	//alert(fullpath.indexOf("index.php"));
	return url;
}


//crossbrowser load function
function addEvent(elm, evType, fn, useCapture)
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Please upgrade your browser to use full functionality on this page");
  }
}


function startEditInline()
{
	var userStatus = document.getElementById("userStatus");
	userStatus.style.display = "none"; 
	var edit = document.getElementById("edit");
	edit.style.display = "block";
	//edit.value = "ssdsd"
	//edit.value = userStatus.innerHTML;
	//alert("value "+edit.value);
	edit.focus();
}
function resetEditInline()
{
	var userStatus = document.getElementById("userStatus");
	userStatus.style.display = "block"; 
	var edit = document.getElementById("edit");
	edit.style.display = "none";
}
function unhighlight(item)
{
	// reset back to body bgColor
	item.style.backgroundColor="#E0FFFF";     
}

function highlight(item)
{
     item.style.backgroundColor="#b2dddd";     
}

function saveData(col)
{
	resetEditInline();
	var str = document.getElementById("txtUserStatus").value;
	if(str == "")
	{
		alert("please insert some value !");return;
	}
		
	var userStatus = document.getElementById("userStatus");
	remotos = new datosServidor;
	userStatus.innerHTML = "Loading... ";
	//alert(encodeURIComponent(str));
	nt = remotos.enviar(urlBase + "?fieldname=" +escape(col)+ "&content="+encodeURIComponent(str)+"&user_id="+document.getElementById("uid").value,"");
	userStatus.innerHTML = nt;
	
	return false;
	//alert(str);
}
function check(str,e){
	
	
    var code;
      if (!e) var e = window.event;
      if (e.keyCode) 
		code = e.keyCode; // IE
      else if (e.which) 
		code = e.which; // Firefox
      if(code == 13){
		saveData(str);
		// Disable postback occur from other place
		return false;
      }
	  // return pressed character
	  return true;
  }

function setNextFocus(obj)
{
alert("setNextFocus "+obj);
  if (event.keyCode == 13){
          //  var obj=document.getElementById(objId);
            if (obj){
			alert(obj);
                obj.focus();
            }
        }
}
function init_hidden_textbox()
{
	
	var userStatus = document.getElementById("userStatus");
	var edit = document.getElementById("txtUserStatus");
	
	edit.value = userStatus.innerHTML;
}
//addEvent(window, "load", editbox_init);
addEvent(window, "load", init_hidden_textbox);